Type CalMesh

	Field m_model:CalModel
	Field m_coreMesh:CalCoreMesh
	Field m_vectorSubmesh:CalSubmesh[]


	Method New()

		m_model = Null
		m_coreMesh = Null
		m_vectorSubmesh = New CalSubmesh[0]
	
	End Method
	
	Function FromCore:CalMesh(coreMesh:CalCoreMesh)
		Local mesh:CalMesh = New CalMesh
		mesh.m_model = Null
		mesh.m_coreMesh = coreMesh
		mesh.m_vectorSubmesh = New CalSubmesh[0]
		
		
		Local vectorCoreSubmesh:CalCoreSubmesh[] = coreMesh.getVectorCoreSubmesh()
		Local submeshCount:Int = vectorCoreSubmesh.length
		
		For Local submeshId:Int = 0 To submeshCount-1
			mesh.m_vectorSubmesh = mesh.m_vectorSubmesh[..mesh.m_vectorSubmesh.length+1]'push(New Cal3D.CalSubmesh(vectorCoreSubmesh[submeshId]))
			mesh.m_vectorSubmesh[mesh.m_vectorSubmesh.length-1] = CalSubmesh.FromCore(vectorCoreSubmesh[submeshId])
		Next
		Return mesh		
	End Function
	
	Method getCoreMesh:CalCoreMesh()
		Return m_coreMesh
	End Method


	Method getSubmesh:CalSubmesh(submeshId:Int)
		If submeshId < 0 Or submeshId >= m_vectorSubmesh.Length Then
			DebugLog "Invalid Submesh ID"
			Return Null
		EndIf
	
		Return m_vectorSubmesh[submeshId]	
	
	End Method
	
	Method getSubmeshCount:Int()
		Return m_vectorSubmesh.length
	End Method
	
	Method getVectorSubmesh:CalSubmesh[]()
		Return m_vectorSubmesh
	End Method
	
	Method setLodLevel(lodLevel:Float)
		For Local submeshId:Int = 0 To m_vectorSubmesh.length-1
			' set the lod level in the submesh
			m_vectorSubmesh[submeshId].setLodLevel(lodLevel)
		Next		
	End Method
	
	Method setMaterialSet(setId:Int)
		For Local submeshId:Int = 0 To m_vectorSubmesh.length
			' get the core material thread id of the submesh
			Local coreMaterialThreadId:Int = m_vectorSubmesh[submeshId].getCoreSubmesh().getCoreMaterialThreadId()
	
			' get the core material id for the given set id in the material thread
			Local coreMaterialId:Int = m_model.getCoreModel().getCoreMaterialIdbyID(coreMaterialThreadId, setId)
	
			' set the new core material id in the submesh
			m_vectorSubmesh[submeshId].setCoreMaterialId(coreMaterialId)
		Next		
	End Method
	
	Method setModel(model:CalModel)
		m_model = model
	End Method
	
	Method disableInternalData()
		For Local submeshId:Int = 0 To m_vectorSubmesh.length
			' disable internal data of the submesh
			m_vectorSubmesh[submeshId].disableInternalData()
		Next		
	End Method

End Type
